package main

import (
	"io"
	"log"
	"net"
	"os"
)

// START OMIT
type loggingConn struct {
	net.Conn // or *net.TCPConn
}

func (c *loggingConn) Read(b []byte) (int, error) {
	n, err := c.Conn.Read(b)
	log.Printf("read %d bytes: %q, err: %v", n, string(b[:n]), err)
	return n, err
}

func main() {
	conn, err := net.Dial("tcp", "towel.blinkenlights.nl:666")
	if err != nil {
		log.Fatal("failed to connect to bofh server:", err)
	}
	bofh := &loggingConn{conn}
	defer bofh.Close()
	io.Copy(os.Stdout, bofh)
}
// STOP OMIT
